<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>下班倒计时</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            min-height: 100vh;
            background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 100%);
            background-size: 400% 400%;
            animation: gradientBG 15s ease infinite;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
            color: #2d3748;
            overflow-x: hidden;
        }
        
        @keyframes gradientBG {
            0% { background-position: 0% 50%; }
            50% { background-position: 100% 50%; }
            100% { background-position: 0% 50%; }
        }
        
        .container {
            width: 100%;
            max-width: 500px;
            background: rgba(255, 255, 255, 0.85);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
            padding: 40px;
            text-align: center;
            position: relative;
            overflow: hidden;
            border: 1px solid rgba(255, 255, 255, 0.3);
            z-index: 10;
        }
        
        h1 {
            font-size: 2.5rem;
            margin-bottom: 30px;
            color: #5e17eb;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
            position: relative;
        }
        
        h1::after {
            content: "⏰";
            position: absolute;
            right: -40px;
            top: -10px;
            font-size: 1.5rem;
            animation: float 3s ease-in-out infinite;
        }
        
        @keyframes float {
            0%, 100% { transform: translateY(0); }
            50% { transform: translateY(-10px); }
        }
        
        .countdown-display {
            font-size: 4.5rem;
            font-weight: 700;
            margin: 30px 0;
            color: #5e17eb;
            letter-spacing: 4px;
            text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.1);
            background: rgba(255, 255, 255, 0.7);
            border-radius: 15px;
            padding: 20px;
            display: flex;
            justify-content: center;
            gap: 10px;
            transition: all 0.3s ease;
        }
        
        .countdown-ended {
            background: rgba(149, 237, 120, 0.7);
            animation: pulseBg 2s infinite;
        }
        
        @keyframes pulseBg {
            0%, 100% { background-color: rgba(149, 237, 120, 0.7); }
            50% { background-color: rgba(112, 210, 255, 0.7); }
        }
        
        .time-unit {
            min-width: 100px;
            position: relative;
        }
        
        .time-label {
            font-size: 1.2rem;
            display: flex;
            justify-content: space-around;
            margin-top: -10px;
            color: #4a5568;
        }
        
        .time-config {
            margin: 30px 0;
            padding: 20px;
            background: rgba(250, 250, 250, 0.8);
            border-radius: 15px;
            position: relative;
        }
        
        .config-group {
            margin: 15px 0;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 15px;
        }
        
        label {
            font-size: 1.2rem;
            font-weight: 500;
        }
        
        input {
            padding: 12px 15px;
            border: 2px solid #e2e8f0;
            border-radius: 10px;
            font-size: 1.1rem;
            text-align: center;
            transition: all 0.3s ease;
            background: white;
        }
        
        input:focus {
            outline: none;
            border-color: #5e17eb;
            box-shadow: 0 0 0 3px rgba(94, 23, 235, 0.2);
        }
        
        button {
            background: #5e17eb;
            color: white;
            border: none;
            padding: 12px 25px;
            font-size: 1.1rem;
            border-radius: 10px;
            cursor: pointer;
            transition: all 0.3s ease;
            font-weight: 600;
            box-shadow: 0 4px 6px rgba(94, 23, 235, 0.3);
            position: relative;
            overflow: hidden;
        }
        
        button::after {
            content: "";
            position: absolute;
            top: 50%;
            left: 50%;
            width: 5px;
            height: 5px;
            background: rgba(255, 255, 255, 0.5);
            opacity: 0;
            border-radius: 100%;
            transform: scale(1, 1) translate(-50%);
            transform-origin: 50% 50%;
        }
        
        button:hover {
            background: #4a10c7;
            transform: translateY(-2px);
            box-shadow: 0 6px 8px rgba(94, 23, 235, 0.4);
        }
        
        button:active::after {
            animation: ripple 0.5s ease-out;
        }
        
        @keyframes ripple {
            0% {
                transform: scale(0, 0);
                opacity: 0.5;
            }
            100% {
                transform: scale(20, 20);
                opacity: 0;
            }
        }
        
        .log-section {
            margin-top: 30px;
            padding: 20px;
            background: rgba(250, 250, 250, 0.8);
            border-radius: 15px;
            max-height: 200px;
            overflow-y: auto;
        }
        
        .log-section h2 {
            margin-bottom: 15px;
            color: #5e17eb;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }
        
        .log-section h2::before {
            content: "📅";
        }
        
        .log-list {
            list-style-type: none;
            text-align: left;
        }
        
        .log-item {
            padding: 10px;
            border-bottom: 1px solid #e2e8f0;
            display: flex;
            justify-content: space-between;
            align-items: center;
            transition: all 0.3s ease;
        }
        
        .log-item:hover {
            background: rgba(94, 23, 235, 0.05);
            transform: translateX(5px);
        }
        
        .log-item:last-child {
            border-bottom: none;
        }
        
        .log-item::before {
            content: "⏱️";
            margin-right: 10px;
            font-size: 1.2rem;
        }
        
        .confetti {
            position: fixed;
            width: 10px;
            height: 10px;
            background-color: #f00;
            opacity: 0.8;
            z-index: 5;
            pointer-events: none;
        }
        
        /* 庆祝弹窗样式 */
        .celebration-popup {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.7);
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            z-index: 1000;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.5s ease;
        }
        
        .celebration-popup.show {
            opacity: 1;
            pointer-events: all;
        }
        
        .celebration-content {
            background: white;
            padding: 40px 60px;
            border-radius: 15px;
            text-align: center;
            transform: translateY(100px);
            animation: fadeUp 0.8s forwards 0.3s;
            position: relative;
            overflow: hidden;
        }
        
        .celebration-content::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: linear-gradient(45deg, #ff9a9e, #fad0c4, #a1c4fd, #c2e9fb);
            background-size: 400% 400%;
            animation: gradientBG 15s ease infinite;
            opacity: 0.2;
            z-index: -1;
        }
        
        @keyframes fadeUp {
            to {
                transform: translateY(0);
            }
        }
        
        .celebration-emoji {
            font-size: 5rem;
            margin-bottom: 20px;
            animation: spin 1s ease-in-out infinite;
        }
        
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        .celebration-text {
            font-size: 3.5rem;
            font-weight: 800;
            color: #ff6b6b;
            margin-bottom: 20px;
            animation: pulse 1.5s ease-in-out infinite;
            text-shadow: 0 0 10px rgba(255, 107, 107, 0.5);
        }
        
        @keyframes pulse {
            0%, 100% { 
                transform: scale(1); 
                text-shadow: 0 0 10px rgba(255, 107, 107, 0.5);
            }
            50% { 
                transform: scale(1.1); 
                text-shadow: 0 0 20px rgba(255, 107, 107, 0.8);
            }
        }
        
        .celebration-subtext {
            font-size: 1.2rem;
            color: #666;
            margin-top: 20px;
            animation: fadeInOut 2s infinite;
        }
        
        @keyframes fadeInOut {
            0%, 100% { opacity: 0.7; }
            50% { opacity: 1; }
        }
        
        /* 响应式设计 */
        @media (max-width: 600px) {
            .countdown-display {
                font-size: 3rem;
            }
            
            .time-unit {
                min-width: 70px;
            }
            
            .container {
                padding: 25px;
            }
            
            .celebration-content {
                padding: 30px;
                width: 90%;
            }
            
            .celebration-text {
                font-size: 2.5rem;
            }
            
            h1 {
                font-size: 2rem;
            }
            
            .celebration-emoji {
                font-size: 3.5rem;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>下班倒计时</h1>
        
        <div class="countdown-display" id="countdown-display">
            <span class="time-unit" id="hours">00</span>
            <span>:</span>
            <span class="time-unit" id="minutes">00</span>
            <span>:</span>
            <span class="time-unit" id="seconds">00</span>
        </div>
        
        <div class="time-label">
            <span>小时</span>
            <span>分钟</span>
            <span>秒</span>
        </div>
        
        <div class="time-config">
            <div class="config-group">
                <label for="off-time">下班时间:</label>
                <input type="time" id="off-time" value="17:30">
            </div>
            <button id="update-btn">更新时间</button>
        </div>
        
        <div class="log-section">
            <h2>下班记录</h2>
            <ul class="log-list" id="log-list">
                <!-- 下班记录将在这里显示 -->
            </ul>
        </div>
    </div>
    
    <!-- 庆祝弹窗 -->
    <div class="celebration-popup" id="celebration-popup">
        <div class="celebration-content">
            <div class="celebration-emoji">🎉🎉</div>
            <div class="celebration-text">下班啦！</div>
            <div class="celebration-subtext">终于可以休息啦！好好享受属于自己的时间吧~</div>
        </div>
    </div>
    
    <!-- 庆祝音效 -->
    <audio id="celebration-sound" preload="auto">
        <source src="https://assets.mixkit.co/sfx/preview/mixkit-happy-bells-notification-937.mp3" type="audio/mpeg">
    </audio>
    
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 获取DOM元素
            const hoursElement = document.getElementById('hours');
            const minutesElement = document.getElementById('minutes');
            const secondsElement = document.getElementById('seconds');
            const countdownDisplay = document.getElementById('countdown-display');
            const offTimeInput = document.getElementById('off-time');
            const updateBtn = document.getElementById('update-btn');
            const logList = document.getElementById('log-list');
            const celebrationPopup = document.getElementById('celebration-popup');
            const celebrationSound = document.getElementById('celebration-sound');
            
            // 下班时间（默认为17:30）
            let targetHour = 17;
            let targetMinute = 30;
            let countdownActive = true;
            let hasTriggeredToday = false;
            let lastTriggeredDate = null;
            
            // 加载保存的下班记录
            loadLogs();
            
            // 设置下班时间
            function setTargetTime() {
                const timeParts = offTimeInput.value.split(':');
                targetHour = parseInt(timeParts[0]);
                targetMinute = parseInt(timeParts[1]);
                
                // 预加载音频，解决自动播放问题
                celebrationSound.play().then(() => {
                    celebrationSound.pause();
                    celebrationSound.currentTime = 0;
                }).catch(e => {});
            }
            
            // 更新倒计时显示
            function updateCountdown() {
                const now = new Date();
                const today = new Date();
                today.setHours(targetHour, targetMinute, 0, 0);
                
                let targetTime = today.getTime();
                
                // 如果当前时间已经超过目标时间，设置为明天的目标时间
                if (now > today) {
                    const tomorrow = new Date(today);
                    tomorrow.setDate(tomorrow.getDate() + 1);
                    targetTime = tomorrow.getTime();
                }
                
                // 计算时间差
                const diff = targetTime - now.getTime();
                
                // 如果倒计时结束 (考虑1秒的误差范围)
                if (diff <= 1000 && diff >= 0 && countdownActive && !hasTriggeredToday) {
                    if (!lastTriggeredDate || new Date().toDateString() !== lastTriggeredDate.toDateString()) {
                        celebrate();
                        hasTriggeredToday = true;
                        lastTriggeredDate = new Date();
                        countdownActive = false;
                        
                        // 重置第二天
                        setTimeout(() => {
                            hasTriggeredToday = false;
                            countdownActive = true;
                        }, 1000 * 60 * 60 * 24); // 24小时后重置
                    }
                    return;
                }
                
                // 计算时、分、秒
                const totalSeconds = Math.floor(diff / 1000);
                const hours = Math.floor(totalSeconds / 3600);
                const minutes = Math.floor((totalSeconds % 3600) / 60);
                const seconds = totalSeconds % 60;
                
                // 更新显示
                hoursElement.textContent = hours.toString().padStart(2, '0');
                minutesElement.textContent = minutes.toString().padStart(2, '0');
                secondsElement.textContent = seconds.toString().padStart(2, '0');
                
                // 如果即将下班（30分钟内），添加动画效果
                if (totalSeconds < 30 * 60) {
                    countdownDisplay.classList.add('countdown-ended');
                } else {
                    countdownDisplay.classList.remove('countdown-ended');
                }
            }
            
            // 庆祝函数 - 显示弹窗、播放音效、记录时间
            function celebrate() {
                // 显示弹窗
                celebrationPopup.classList.add('show');
                
                // 播放音效
                celebrationSound.currentTime = 0;
                celebrationSound.play().catch(e => console.log("音频播放失败:", e));
                
                // 记录下班时间
                const now = new Date();
                const dateString = now.toLocaleDateString('zh-CN', {
                    year: 'numeric',
                    month: 'long',
                    day: 'numeric'
                });
                const timeString = now.toLocaleTimeString('zh-CN', {
                    hour: '2-digit',
                    minute: '2-digit'
                });
                
                addLog(`${dateString} ${timeString} 下班啦！🎉🎉`);
                
                // 创建五彩纸屑效果
                createConfetti();
                
                // 10秒后关闭弹窗
                setTimeout(() => {
                    celebrationPopup.classList.remove('show');
                }, 10000);
            }
            
            // 创建五彩纸屑效果
            function createConfetti() {
                const colors = ['#ff6b6b', '#4a90e2', '#f5a623', '#7ed321', '#bd10e0'];
                
                for (let i = 0; i < 150; i++) {
                    const confetti = document.createElement('div');
                    confetti.className = 'confetti';
                    confetti.style.left = Math.random() * 100 + 'vw';
                    confetti.style.top = '-10px';
                    confetti.style.backgroundColor = colors[Math.floor(Math.random() * colors.length)];
                    confetti.style.width = Math.random() * 10 + 5 + 'px';
                    confetti.style.height = confetti.style.width;
                    confetti.style.opacity = Math.random() * 0.5 + 0.5;
                    document.body.appendChild(confetti);
                    
                    // 动画
                    const animation = confetti.animate([
                        { transform: 'translateY(0) rotate(0deg)', opacity: 1 },
                        { transform: `translateY(${window.innerHeight}px) rotate(${Math.random() * 360}deg)`, opacity: 0 }
                    ], {
                        duration: Math.random() * 3000 + 2000,
                        easing: 'cubic-bezier(0.1, 0.8, 0.2, 1)'
                    });
                    
                    // 动画结束后移除元素
                    animation.onfinish = () => confetti.remove();
                }
            }
            
            // 添加下班记录
            function addLog(message) {
                const logItem = document.createElement('li');
                logItem.className = 'log-item';
                logItem.textContent = message;
                logList.insertBefore(logItem, logList.firstChild);
                
                saveLogs();
            }
            
            // 保存下班记录到localStorage
            function saveLogs() {
                const logs = [];
                document.querySelectorAll('.log-item').forEach(item => {
                    logs.push(item.textContent);
                });
                localStorage.setItem('offWorkLogs', JSON.stringify(logs));
            }
            
            // 从localStorage加载下班记录
            function loadLogs() {
                const savedLogs = localStorage.getItem('offWorkLogs');
                if (savedLogs) {
                    const logs = JSON.parse(savedLogs);
                    logs.forEach(log => {
                        const logItem = document.createElement('li');
                        logItem.className = 'log-item';
                        logItem.textContent = log;
                        logList.appendChild(logItem);
                    });
                }
            }
            
            // 事件监听器
            updateBtn.addEventListener('click', setTargetTime);
            offTimeInput.addEventListener('change', setTargetTime);
            
            // 初始化倒计时
            setTargetTime();
            updateCountdown();
            setInterval(updateCountdown, 1000);
        });
    </script>
</body>
</html>